What is/are the Scala way(s) to implement this Java "byte[] to Hex" class

Posted by nicerobot on Stack Overflow See other posts from Stack Overflow or by nicerobot
Published on 2010-05-03T04:51:20Z Indexed on 2010/05/03 4:58 UTC
Read the original article Hit count: 174

Filed under:
|
|

I'm specifically interested in Scala (2.8) techniques for building strings with formats as well as interesting ways to make such a capability easily accessible where it's useful (lists of bytes, String, ...?)..

public class Hex {
  public static String valueOf (final byte buf[]) {
    if (null == buf) {
      return null;
    }
    final StringBuilder sb = new StringBuilder(buf.length * 2);
    for (final byte b : buf) {
      sb.append(String.format("%02X", b & 0xff));
    }
    return sb.toString();
  }

  public static String valueOf (final Byteable o) {
    return valueOf(o.toByteArray());
  }
}

This is only a learning exercise (so the utility and implementation of the Java isn't a concern.)

Thanks

© Stack Overflow or respective owner

Related posts about scala

Related posts about beginner